#ifndef DEPARTMENTHPP
#define DEPARTMENTHPP

#include <string>
#include <vector>
#include <experimental/random>

#include "product.hpp"
#include "employee.hpp"

class Department
{
private:
    std::string description;
    std::vector<Product> & products;
    std::vector<Employee> & employees;
public:
    std::string get_description();
    float get_revenue();
    void sell();
 
    Department
    (
        std::string description, 
        std::vector<Product> & products, 
        std::vector<Employee> & employees
    );
};

Department::Department
(
    std::string description, 
    std::vector<Product> & products, 
    std::vector<Employee> & employees
)
    : description(description), products(products), employees(employees)
{
    std::cout << "department " << description << " created\n";
    std::cout << products.size() << " products and " << employees.size() << " employees\n";
}

std::string Department::get_description()
{
    return this->description;
}

float Department::get_revenue()
{
    float revenue = 0;
    // sum revenues
    for (Employee employee : employees)
        revenue += employee.get_revenue();
    return revenue;
}

void Department::sell()
{
    // use gods hand to choose
    int chosen_product = std::experimental::randint(0, (int) this->products.size() - 1);
    int chosen_employee = std::experimental::randint(0, (int) this->employees.size() - 1);

    // get chosen product
    auto product = products[chosen_product];
    // add revenue to chosen employee
    employees[chosen_employee].add_revenue(product.get_price());
    // console output
    std::cout << chosen_product << " (costing " << product.get_price() << ") sold!\n";
    // pop the now sold product
    products.erase(products.begin() + chosen_product);
}

#endif